home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SOURCES / C / SCHEME.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-08  |  29.0 KB  |  896 lines

  1. /* SCHEME.H
  2.  ************************************************************************
  3.  *                                    *
  4.  *        PC Scheme/Geneva 4.00 Borland C code            *
  5.  *                                    *
  6.  * (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT        *
  7.  * (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva    *
  8.  *                                    *
  9.  *----------------------------------------------------------------------*
  10.  *                                    *
  11.  *        Scheme Data Declaration for Borland C            *
  12.  *                                    *
  13.  *----------------------------------------------------------------------*
  14.  *                                    *
  15.  * Created by: John Jensen        Date: 1985            *
  16.  * Revision history:                            *
  17.  * - 18 Jun 92:    Renaissance (Borland Compilers, ...)            *
  18.  *                                    *
  19.  *                    ``In nomine omnipotentii dei''    *
  20.  ************************************************************************/
  21.  
  22. #define VERSIONSTR    "PC Scheme/Geneva " VERSION ", " __DATE__
  23. #define TEXASRIGHTS    "Copyright (c) 1988 Texas Instruments - all rights reserved."
  24. #define GENEVARIGHTS    "Copyright (c) 1992, 1993 L. Bartholdi & M. Vuilleumier, University of Geneva."
  25. #define    RESTRICTIONS    "Use of the following program for any military usage is strictly forbidden.\n"
  26.  
  27. /* Port constants */
  28.  
  29. #define    BUFFSIZE    0x100
  30.  
  31. #define    W_WRAP        0x01        /* 00000001 */
  32. #define    W_TRANS     0x02        /* 00000010 */
  33.     
  34. #define READ_PRIVATE    0x0001        /* 00000000 00000001 */
  35. #define    READ_OPEN    0x0002        /* 00000000 00000010 */
  36. #define    READ_MODE    0x0003        /* 00000000 00000011 */
  37. #define WRITE_PRIVATE    0x0004        /* 00000000 00000100 */
  38. #define    WRITE_OPEN    0x0008        /* 00000000 00001000 */
  39. #define    WRITE_MODE    0x000c        /* 00000000 00001100 */
  40. #define PORT_OPEN    0x000f        /* 00000000 00001111 */
  41. #define    PORT_SHARED    0x0020        /* 00000000 00100000 */
  42. #define    PORT_TYPE    0x0030        /* 00000000 00110000 */
  43. #define    PORT_BINARY    0x0040        /* 00000000 01000000 */
  44. #define    PORT_FLUSHED    0x0080        /* 00000000 10000000 */
  45. #define PORT_WRAP    0x0100        /* 00000001 00000000 */
  46. #define PORT_TRANSCRIPT 0x0200        /* 00000010 00000000 */
  47. #define PORT_LOCKED    0x0400        /* 00000100 00000000 */
  48. #define PORT_NEW    0x0800        /* 00001000 00000000 */
  49.  
  50. #define    READ_CLOSED    0x0000        /* 00000000 00000000 */
  51. #define    READ_PROTECTED    0x0001        /* 00000000 00000001 */
  52. #define    READ_SHARED    0x0002        /* 00000000 00000010 */
  53. #define    READ_EXCLUSIVE    0x0003        /* 00000000 00000011 */
  54. #define    WRITE_CLOSED    0x0000        /* 00000000 00000000 */
  55. #define    WRITE_PROTECTED    0x0004        /* 00000000 00000100 */
  56. #define    WRITE_SHARED    0x0008        /* 00000000 00001000 */
  57. #define    WRITE_EXCLUSIVE    0x000c        /* 00000000 00001100 */
  58. #define    TYPE_WINDOW    0x0000        /* 00000000 00000000 */
  59. #define    TYPE_SOFTWARE    0x0010        /* 00000000 00010000 */
  60. #define    TYPE_STRING    0x0020        /* 00000000 00100000 */
  61. #define    TYPE_FILE    0x0030        /* 00000000 00110000 */
  62.  
  63. #define WINDOW_ULROW          2
  64. #define WINDOW_ULCOL          3
  65. #define WINDOW_NROWS        4
  66. #define WINDOW_NCOLS        5
  67. #define WINDOW_ATTRIBUTES       7
  68.  
  69. #define    BELL        0x07        /* Standard ascii constants */
  70. #define    BACKSPACE    0x08
  71. #define    TAB        0x09
  72. #define    LF        0x0a
  73. #define    CR        0x0d
  74. #define    CTRL_Z        0x1a
  75. #define    ESCAPE        0x1b
  76. #define    SPACE        0x20
  77. #define    DEL        0x7f    /* ctrl-backspace */
  78.  
  79. #define    ENTER_KEY    0x0d00        /* Extended key codes */
  80. #define    HOME_KEY    0x4700
  81. #define    UP_KEY        0x4800
  82. #define    LEFT_KEY    0x4b00
  83. #define    RIGHT_KEY    0x4d00
  84. #define    END_KEY        0x4f00
  85. #define    DOWN_KEY    0x5000
  86. #define    INSERT_KEY    0x5200
  87. #define    DELETE_KEY    0x5300
  88. #define    CTRL_LEFT_KEY    0x7300
  89. #define    CTRL_RIGHT_KEY    0x7400
  90. #define    CTRL_END_KEY    0x7500
  91. #define    CTRL_HOME_KEY    0x7700
  92. #define    CTRL_DEL_KEY    0x9300    /* exists since DOS 5.0 (or 4.0 ?) */
  93. #define MACRO_CONTINUE    0x1111
  94.  
  95. /************ scheme pointer structure & register class *************/
  96.  
  97. typedef    struct {
  98.     unsigned char   page;
  99.     unsigned disp;
  100. }    POINTER;
  101.  
  102. class    VM_REG {
  103. public:
  104.     unsigned    disp;
  105.     unsigned    page;
  106. } ;
  107.  
  108. class    REG : public VM_REG {
  109. private:
  110.     REG        *next;
  111.     static    REG    *first;
  112. public:
  113.     static    void    mark(void);
  114.     static    void    relocate(void);
  115.     static    int    check(void);
  116.     static    void    cleanup(REG *, REG *);
  117.     REG&        operator = (REG& r)
  118.         { disp = r.disp; page = r.page; return *this; }
  119.     REG&        operator = (VM_REG& r)
  120.         { disp = r.disp; page = r.page; return *this; }
  121.     REG(const REG& r)
  122.         { disp = r.disp; page = r.page; next = first; first = this; }
  123.     REG(const VM_REG& r)
  124.         { disp = r.disp; page = r.page; next = first; first = this; }
  125.     REG(const POINTER far& r)
  126.         { disp = r.disp; page = r.page; next = first; first = this; }
  127.     REG(unsigned d = 0, unsigned p = 0)
  128.         { disp = d; page = p; next = first; first = this; };
  129.     ~REG(void);
  130. } ;
  131.  
  132. typedef VM_REG        *REGPTR;
  133.  
  134. /****************** scheme objects *********************/
  135.  
  136. typedef struct {
  137.     union {
  138.         POINTER car;
  139.         struct {
  140.             char    __dummy1;
  141.             unsigned    next;
  142.         }    free;
  143.     };
  144.     POINTER cdr;
  145. }       LIST;
  146. #define    FREELISTDEF    0x7f
  147.  
  148. typedef    struct {
  149.     unsigned    len;
  150.     char    sign;
  151.     unsigned    data[1];
  152. }    BIGDATA;
  153.  
  154. typedef    struct {
  155.     unsigned char    type;
  156.     BIGDATA    data;
  157. }    BIGNUM;
  158.  
  159. typedef    struct {
  160.     unsigned char    type;
  161.     union {
  162.         double    data;
  163.         POINTER    ptr;
  164.         unsigned    next;
  165.     };
  166. }    FLONUM;
  167.  
  168. typedef    struct {
  169.     unsigned char    type;
  170.     unsigned    len;
  171.     POINTER    data[1];
  172. }    VECTOR;
  173.  
  174. typedef    struct {
  175.     unsigned char    type;
  176.     unsigned    len;
  177.     POINTER    link;
  178.     unsigned char    hash;
  179.     char    buffer[1];
  180. }    SYMBOL;
  181.  
  182. typedef    struct {
  183.     unsigned char    type;
  184.     int        len;    /* negative for small strings */
  185.     char    buffer[1];
  186. }    STRING;
  187.  
  188. typedef    struct {
  189.     unsigned char    type;
  190.     unsigned    len;
  191.     POINTER    info;
  192.     POINTER    heap;
  193.     POINTER    codeblock;
  194.     POINTER    entry;
  195.     POINTER    arg;
  196.     char    debug[1];
  197. }    CLOSURE;
  198.  
  199. typedef    struct {
  200.     unsigned char    type;
  201.     unsigned    len;
  202.     POINTER    base;
  203.     POINTER    codebase;
  204.     POINTER    ret;
  205.     POINTER    dlink;
  206.     POINTER    fluid;
  207.     POINTER    stack;
  208.     POINTER    global;
  209.     char    data[1];
  210. }    CONTINUATION;
  211.  
  212. typedef    struct {
  213.     unsigned char    type;
  214.     unsigned    len;
  215.     POINTER    entry;
  216.     POINTER    constants[1];
  217. }    CODEBLOCK;
  218.  
  219. typedef    struct {
  220.     unsigned char    type;
  221.     unsigned    len;
  222.     unsigned char    data[1];
  223. }    I86BLOCK;
  224.  
  225. typedef    struct {
  226.     unsigned char    type;
  227.     unsigned    len;
  228.     POINTER    parent;
  229.     POINTER    names;
  230.     POINTER    values;
  231. }    ENVIRONMENT;
  232.  
  233. typedef    struct {
  234.     unsigned char    type;
  235.     unsigned    len;
  236.     POINTER        ptr;
  237.     unsigned    flags;
  238.     unsigned    handle;            /// union with border & text
  239.     unsigned    curline;
  240.     unsigned    curcol;
  241.     union {
  242.         unsigned    chunk;        /// destroy
  243.         unsigned    ulline;        /// change to unsigned long
  244.     };
  245.     unsigned    ulcol;            /// change to unsigned long
  246.     unsigned    nlines;
  247.     unsigned    ncols;
  248.     unsigned    border;
  249.     unsigned    text;
  250.     unsigned    winflags;        /// destroy, move to flags
  251.     unsigned    bufpos;             ////
  252.     unsigned    bufend;            //// leave only in window
  253.     unsigned char    buffer[BUFFSIZE];    ////
  254.     POINTER        next;            /// move near ptr
  255. }    PORT;
  256.  
  257. typedef    struct {
  258.     POINTER    codeblock;
  259.     POINTER    ret;
  260.     POINTER    dlink;
  261.     POINTER    heap;
  262.     POINTER    slink;
  263.     POINTER    closure;
  264.     POINTER    data[1];
  265. }    STACKFRAME;
  266.  
  267. typedef    union {
  268.     struct {
  269.         unsigned char    type;
  270.         unsigned    len;
  271.     }    _;
  272.     LIST    list;
  273.     BIGNUM    bignum;
  274.     FLONUM    flonum;
  275.     VECTOR    vector;
  276.     SYMBOL    symbol;
  277.     STRING    string;
  278.     CLOSURE    closure;
  279.     CONTINUATION    continuation;
  280.     CODEBLOCK    codeblock;
  281.     I86BLOCK    i86block;
  282.     ENVIRONMENT    environment;
  283.     PORT    port;
  284. }    OBJECT;
  285. typedef    OBJECT    *OBJPTR;
  286. typedef    OBJECT    far    *SCHEMEOBJ;
  287.  
  288. /* escape and other var-args functions value passing structures */
  289.  
  290. #define    NUMARGS    62
  291.  
  292. typedef union {
  293.     long    i;
  294.     short    b;
  295.     char    c;
  296.     double  f;
  297.     char    *s;
  298.     VM_REG    r;
  299.     }    LINKVAL;
  300.  
  301. typedef enum {
  302.     NOVALUE, BOOLEAN, INTEGER, FLOAT, CHARACTER, STR, STATSTR, SCHEME,
  303.     ERROR = -1
  304.     }    LINKTYPE;
  305.  
  306. typedef struct {
  307.     LINKVAL    item;
  308.     LINKTYPE type;
  309.     }       LINKARG;
  310.  
  311. #define STRorNIL     (result->s ? STR : BOOLEAN)
  312. #define STATSTRorNIL     (result->s ? STATSTR : BOOLEAN)
  313.  
  314. /* Data conversion macros */
  315. /*
  316.  * Adjust page number- this macro converts a logical page number to the
  317.  * representation which is stored in the interpreter's registers and
  318.  * pointers.  "CORRPAGE" performs the reverse transformation
  319.  */
  320. #define ADJPAGE(x)      (((unsigned char) (x)) << 1)
  321. /*
  322.  * Correct page number- this macro converts the interpreter's encoding of a
  323.  * page number into the logical page number.  "ADJPAGE" performs the reverse
  324.  * transformation.
  325.  */
  326. #define CORRPAGE(x)     (((unsigned char) (x)) >> 1)
  327.  
  328. /* Fetch value for Character (immediate) from pointer */
  329. #define get_char(pg,ds) (((unsigned char) (ds)) & 0xff)
  330.  
  331. #define TRUE 1
  332. #define FALSE 0
  333. #ifndef NULL
  334. #define NULL 0
  335. #endif
  336.  
  337. /* consts for get_port() */
  338. #define INPUT_PORT    0x00
  339. #define OUTPUT_PORT    0x01
  340.  
  341. /* consts for sprint() */
  342. #define    SP_OUTPUT    0x01
  343. #define    SP_SEPARE    0x02
  344. extern char    show;
  345.  
  346. /* Page Management Table Definitions */
  347. #define NUMPAGES 128                    /* maximum number of pages */
  348. #define DEDPAGES 8                      /* Number of dedicated pages */
  349. #define MIN_PAGESIZE 0x0C00             /* minimal page size */
  350.  
  351. #define HT_SIZE 211                     /* the oblist's hash table size */
  352. #define STKSIZE 300                     /* the stack's length (pointers) */
  353. #define BLK_OVHD 3                      /* number of overhead bytes in a block header */
  354. #define NUM_REGS 64                     /* number of registers in the Scheme VM */
  355.  
  356. enum {
  357.     LISTTYPE = 0, FIXTYPE = 2, FLOTYPE = 4, BIGTYPE = 6, SYMTYPE = 8,
  358.     STRTYPE = 10, VECTTYPE = 12, CONTTYPE = 14, CLOSTYPE = 16, FREETYPE = 18,
  359.     CODETYPE = 20, I86TYPE = 22, PORTTYPE = 24, CHARTYPE = 26, ENVTYPE = 28,
  360.     NUMTYPES = 15
  361. };
  362.  
  363. #define EOFERR 1                        /* Codes for function ERRMSG */
  364. #define DOTERR 2
  365. #define QUOTERR 3
  366. #define RPARERR 4
  367. #define OVERERR 5
  368. #define DIV0ERR 6
  369. #define SHARPERR 7
  370. #define FULLERR -1
  371. #define PORTERR -2
  372. #define HEAPERR -3
  373.  
  374. #define BUFSIZE 80
  375. #define DEFAULT_LENGTH 64               /* default dump length */
  376.  
  377. #define SMALL_SIZE 1024                 /* a "small" length for a block */
  378.  
  379. #define SPECCHAR 1                      /* special page of characters */
  380. #define SPECFIX 3                       /* special page of fixnums */
  381. #define SPECFLO 4                       /* special page of flonums */
  382. #define SPECSYM 5                       /* special page of symbols */
  383. #define SPECPOR 6                       /* special page of ports */
  384. #define SPECCODE 7                      /* code page for the bootstrap loader */
  385. #define    ENV_PAGE 8            /* page for initial environments */
  386.  
  387. #define END_LIST 0x7FFF                 /* end of linked list marker */
  388.  
  389. #define NIL_PAGE 0                      /* Location of "nil" */
  390. #define NIL_DISP 0
  391. #define T_PAGE SPECSYM                  /* Location of "t" (for true) */
  392. #define T_DISP 0x0000
  393. #define UN_PAGE SPECSYM                 /* Location of "#!unassigned" */
  394. #define UN_DISP 0x0009
  395. #define NTN_PAGE SPECSYM                /* Location of "#!not-a-number" */
  396. #define NTN_DISP 0x001C
  397. #define OVR_PAGE SPECSYM                /* Location of overflow designator */
  398. #define OVR_DISP 0x001C                 /* (same as "not a number" for now) */
  399. #define DIV0_PAGE SPECSYM               /* Location of divide-by-zero designator */
  400. #define DIV0_DISP 0x001C                /* (same as "not a number" for now) */
  401. #define IN_PAGE SPECPOR                 /* Location of standard input port */
  402. #define IN_DISP 0
  403. #define OUT_PAGE SPECPOR                /* Location of standard output port */
  404. #define OUT_DISP 0                      /* input=output for standard console device */
  405. #define WHO_PAGE SPECPOR                /* Location of "who-line" port */
  406. #define WHO_DISP (sizeof(PORT))
  407. #define EOF_PAGE SPECSYM                /* Location of non-interned "**eof**" symbol */
  408. #define EOF_DISP 0x0031
  409. #define NPR_PAGE SPECSYM                /* Location of "#!unprintable" */
  410. #define NPR_DISP 0x003D
  411.  
  412. #define ADD_OP 0                        /* addition */
  413. #define SUB_OP 1                        /* subtraction */
  414. #define MUL_OP 2                        /* multiplication */
  415. #define DIV_OP 3                        /* divide */
  416. #define REM_OP 4                        /* remainder */
  417. #define AND_OP 5                        /* bitwise and */
  418. #define OR_OP 6                         /* bitwise or */
  419. #define MINUS_OP 7                      /* minus */
  420. #define EQ_OP 8                         /* equal comparison */
  421. #define NE_OP 9                         /* not equal comparison */
  422. #define LT_OP 10                        /* less than comparison */
  423. #define GT_OP 11                        /* greater than comparison */
  424. #define LE_OP 12                        /* less than or equal comparison */
  425. #define GE_OP 13                        /* greater than or equal comparison */
  426. #define ABS_OP 14                       /* absolute value */
  427. #define QUOT_OP 15                      /* quotient (integers) */
  428. #define TRUNC_OP 16                     /* truncate */
  429. #define FLOOR_OP 17                     /* floor */
  430. #define CEIL_OP 18                      /* ceiling */
  431. #define ROUND_OP 19                     /* round */
  432. #define FLOAT_OP 20                     /* float */
  433. #define ZERO_OP 21                      /* zero? */
  434. #define POS_OP 22                       /* positive? */
  435. #define NEG_OP 23                       /* negative? */
  436. #define XOR_OP 24                       /* bitwise xor */
  437. #define    DIVIDE_OP 25            /* divide (integers) */
  438. #define    MOD_OP 26            /* modulo */
  439.  
  440. #define T_RUN   0x02                    /* how t_inst works */
  441. #define T_DISPLAY       0x01            
  442.  
  443. typedef enum {                          /* return values for interpreter & debugger */
  444.     PROCEED,
  445.     HALT,
  446.     SDEBUG,
  447.     CLOBBERED
  448. }       RETVALUE;
  449.  
  450.                     /* Numeric Error Codes */
  451. #define REF_GLOBAL_ERROR 1              /* reference of unbound global variable */
  452. #define SET_GLOBAL_ERROR 2              /* SET! error-- global not defined */
  453. #define REF_LEXICAL_ERROR 3             /* reference of unbound lexical variable */
  454. #define SET_LEXICAL_ERROR 4             /* SET! error-- lexical variable not defined */
  455. #define REF_FLUID_ERROR 5               /* reference of unbound fluid variable */
  456. #define SET_FLUID_ERROR 6               /* SET-FLUID! error-- fluid not bound */
  457. #define VECTOR_OFFSET_ERROR 7           /* vector index out of range */
  458. #define STRING_OFFSET_ERROR 8           /* string index out of range */
  459. #define SUBSTRING_RANGE_ERROR 9         /* invalid substring range */
  460. #define INVALID_OPERAND_ERROR 10        /* invalid operand to VM instruction */
  461. #define SHIFT_BREAK_CONDITION 11        /* SHFT-BRK key was depressed by user */
  462. #define NON_PROCEDURE_ERROR 12          /* attempted to call non-procedural object */
  463. #define TIMEOUT_CONDITION 13            /* timer interrupt */
  464. #define WINDOW_FAULT_CONDITION 14       /* attempt to do I/O to a de-exposed window */
  465. #define FLONUM_OVERFLOW_ERROR 15        /* flonum overflow/underflow */
  466. #define ZERO_DIVIDE_ERROR 16            /* division by zero */
  467. #define NUMERIC_OPERAND_ERROR 17        /* non-numeric operand */
  468. #define APPLY_ARG_LIMIT_ERROR 18        /* too many arguments for APPLY to handle */
  469. #define VECTOR_SIZE_LIMIT_ERROR 19      /* vector too big */
  470. #define STRING_SIZE_LIMIT_ERROR 20      /* string too big */
  471. #define IO_ERROR_START 21               /* Errors from 21 and 84 are DOS I/O errors */
  472. #define DOS_FATAL_ERROR 21              /* Generic fatal I/O error */
  473. #define EXTEND_START_ERROR_CODE 1       /* Extended error codes from INT 59h */
  474. #define EXTEND_END_ERROR_CODE 88
  475. #define DISK_FULL_ERROR 200             /* Our own home-grown error codes */
  476. #define LAST_ERROR  200                 /* Future errors should start here */
  477.  
  478. extern char    *pcsrsenv;        /* "pcs-reserved-symbols-environment" */
  479. extern char    *pcsksenv;        /* "pcs-known-symbols-environment" */
  480.  
  481. extern int    vm_debug;               /* VM debug mode flag */
  482. extern char    s_break;                /* shift-break indicator */
  483. extern char    emspages;        /* pages swapped in EMMS */
  484.  
  485. typedef union {
  486.     unsigned        word;
  487.     struct {
  488.     unsigned        characters:1;   /* Less significant bit */
  489.     unsigned        code:1;
  490.     unsigned        ports:1;
  491.     unsigned        i86code:1;
  492.     unsigned        closure:1;
  493.     unsigned        continu:1;
  494.     unsigned        readonly:1;
  495.     unsigned        nomemory:1;     /* MSBit of LSByte */
  496.     unsigned        arrays:1;       /* LSBit of MSByte */
  497.     unsigned        strings:1;
  498.     unsigned        symbols:1;
  499.     unsigned        bignums:1;
  500.     unsigned        flonums:1;
  501.     unsigned        fixnums:1;
  502.     unsigned        listcell:1;
  503.     unsigned        atom:1;         /* Most significant bit */
  504.     }       FLAGS;
  505. }       ATTRIBUTES;
  506.  
  507. extern ATTRIBUTES       attrib[NUMPAGES];/* Page Attribute Bits */
  508. extern unsigned nextcell[NUMPAGES];     /* Next Available Cell Pointers */
  509. extern unsigned pagelink[NUMPAGES];     /* Next Page of Same Type */
  510. extern unsigned ptype[NUMPAGES];        /* Page Type Index */
  511. extern unsigned psize[NUMPAGES];        /* Page Size Table */
  512.  
  513. extern ATTRIBUTES pageattr[NUMTYPES];   /* Page attribute initialization table */
  514. extern unsigned pagelist[NUMTYPES];     /* Page allocation table (by types) */
  515.  
  516. extern unsigned listpage;               /* Page for List Cell allocation */
  517. extern unsigned fixpage;                /* Page for Fixnum allocation */
  518. extern unsigned flopage;                /* Page for Flonum allocation */
  519. extern unsigned bigpage;                /* Page for Bignum allocation */
  520. extern unsigned sympage;                /* Page for Symbol allocation */
  521. extern unsigned strpage;                /* Page for String allocation */
  522. extern unsigned vectpage;               /* Page for Vector allocation */
  523. extern unsigned contpage;               /* Page for Continuation allocation */
  524. extern unsigned clospage;               /* Page for Closure allocation */
  525. extern unsigned freepage;               /* Free page allocation list header */
  526. extern unsigned codepage;               /* Page for Code Block allocation */
  527. extern unsigned i86page;                /* Page for inline code allocation */
  528. extern unsigned portpage;               /* Page for Port cell allocation */
  529. extern unsigned charpage;               /* Page for characters */
  530. extern unsigned envpage;                /* Page for environments */
  531.  
  532. extern unsigned nextpage;               /* Next Page # for Allocation in Address Space */
  533. extern unsigned lastpage;               /* Last Page # for Allocation in Address Space */
  534. extern unsigned nextpara;               /* Next Paragraph Address for Allocation */
  535.  
  536.                     /* Scheme's Virtual Registers */
  537. extern VM_REG    regs[NUM_REGS];
  538. extern REG      fnv_save, stl_save;
  539. extern REG      nil_reg;
  540. extern REG      tmp_reg, tm2_reg, fnv_reg, gnv_reg, cb_reg, prev_reg;
  541. extern REG      console_reg;
  542. extern REG      trns_reg;               /* transcript file pointer */
  543. extern REG    quote_reg;              /* Location of "quote" */
  544. extern REG    port_reg, macro_reg;    /* current IO port properties */
  545.  
  546. extern unsigned frameptr, base, condcode, s_pc, topofstack;
  547.  
  548. extern int    prn_handle;
  549. extern int    handlee, pflags;
  550. extern int    nlines, ncols;
  551. extern int    ulline, ulcol;
  552. extern int    curline, curcol;
  553. extern unsigned    t_attrib, insert_m;
  554. extern int    index, vidmode;
  555.  
  556. extern  POINTER s_stack[STKSIZE];       
  557.                     /* Hash Table */
  558. extern unsigned char    hash_page[HT_SIZE];
  559. extern unsigned hash_disp[HT_SIZE];
  560.  
  561.                     /* Property List Hash Table */
  562. extern unsigned char    prop_page[HT_SIZE];
  563. extern unsigned prop_disp[HT_SIZE];
  564.  
  565.                     /* State Variables for (reset) and (scheme-reset) */
  566. extern unsigned fp_save, rst_ent;
  567.  
  568. #define    SPECIALCHARS    8
  569. extern char    *spchars[SPECIALCHARS];
  570.  
  571.                     /* Scheme Function Macros */
  572. #define alloc_sym(dest,len) alloc_block(dest,SYMTYPE,len+sizeof(POINTER)+1)
  573. #define outchar(ch) givechar(ch)
  574. #define outtext(str,len) printstr(str,len)
  575.  
  576.                     /* International Case Conversion Macros */
  577. extern unsigned char     locases[256];
  578. extern unsigned char     hicases[256];
  579. #undef tolower
  580. #define tolower(c) locases[(c)]
  581. #undef toupper
  582. #define toupper(c) hicases[(c)]
  583. #undef islower
  584. #define islower(c) ((c)!=hicases[(c)])
  585. #undef isupper
  586. #define isupper(c) ((c)!=locases[(c)])
  587. #undef isdigit
  588. #define isdigit(c) isdig((c),10)
  589. #undef isxdigit
  590. #define isxdigit(c) isdig((c),16)
  591.  
  592. #ifndef min
  593. #define max(a,b)    (((a) > (b)) ? (a) : (b))
  594. #define min(a,b)    (((a) < (b)) ? (a) : (b))
  595. #endif
  596.  
  597. #define FIXNUM(n)       ( REG((n), ADJPAGE(SPECFIX)) )
  598.  
  599. #define    internimm(reg,name)    intern( reg, name, sizeof name - 1 );
  600.  
  601. /* test equality (eq? -ness) of two registers or pointers */
  602. #define eq(r1,r2) ( (r1)->disp == (r2)->disp && (r1)->page == (r2)->page )
  603.  
  604. /* assign a pointer to a register or vice-versa */
  605. #define load(r1,r2) (r1)->disp = (r2)->disp; (r1)->page = (r2)->page;
  606.  
  607. #define take_caar(reg) take_car(reg); take_car(reg)
  608. #define take_cadr(reg) take_cdr(reg); take_car(reg)
  609. #define take_cddr(reg) take_cdr(reg); take_cdr(reg)
  610.  
  611. /* function prototypes */
  612.  
  613. extern  "C" {
  614.  
  615. int        aceiling(REGPTR);
  616. void        accounting(void);
  617. void        adj4bord(int *, int *, int *, int *);
  618. int        afloor(REGPTR);
  619. void        alloc_big_block(REGPTR, unsigned, unsigned);
  620. void        alloc_block(REGPTR, unsigned, unsigned);
  621. void        alloc_fixnum(REGPTR, unsigned);
  622. void        alloc_flonum(REGPTR, double);
  623. void        alloc_int(REGPTR, BIGDATA *);
  624. void        alloc_list_cell(REGPTR);
  625. unsigned    alloc_page(unsigned, unsigned);
  626. void        alloc_string(REGPTR, char *);
  627. void        arg_err(REGPTR, int, char *);
  628. int        arith1(int, REGPTR);
  629. int        arith2(int, REGPTR, REGPTR);
  630. int        around(REGPTR);
  631. void        asetcdr(REGPTR, REGPTR);
  632. int        asm_link(int, ...);
  633. int        atruncate(REGPTR);
  634.  
  635. int        bid_task(char *, char *, char *, char *);
  636. void        big2asc(BIGDATA *, char *);
  637. int        big2flo(BIGDATA *, double *);
  638. void        bigadd(BIGDATA *, BIGDATA *);
  639. int        bigdiv(BIGDATA *, BIGDATA *, BIGDATA *);
  640. void        bigsub(BIGDATA *, BIGDATA *);
  641. void        bigmul(BIGDATA *, BIGDATA *, BIGDATA *);
  642. void        bool2scm(REGPTR, int);
  643. unsigned    blk2pbuf(unsigned, unsigned, char *, unsigned, char, int);
  644. void        buildint(void *, char *, int);
  645.  
  646. void        c_pop(REGPTR);
  647. void        c_push(REGPTR);
  648. void        checkstack();
  649. int        clear_window(REGPTR);
  650. void        cons(REGPTR, REGPTR, REGPTR);
  651. void        copy_blk(REGPTR, REGPTR);
  652. int        copy_file(char *, char *);
  653. void        copybig(unsigned, unsigned, BIGDATA *);
  654. void        cputype(REGPTR, REGPTR);
  655. void        crst_tim(REGPTR);
  656. int        cset_tim(REGPTR);
  657.  
  658. unsigned    digval(char);
  659. char        *dir1(char *, char *);
  660. char        *dir2(int, char *);
  661. void        disassemble(char *, unsigned);
  662. void        dos_error(int, int, REGPTR);
  663.  
  664. int        eq_lookup(REGPTR, REGPTR);
  665. void        enlarge(REGPTR, long);
  666. void        errmsg(int);
  667.  
  668. int        fasl(REGPTR);
  669. long        filesize(char *);
  670. unsigned    find_big_block(unsigned);
  671. int        find_block(REGPTR, int, int, int);
  672. void        fix2big(signed, BIGDATA *);
  673. void        fixflo(REGPTR, double);
  674. void        fix_intr(void);
  675. void        flo2big(double, BIGDATA *);
  676. char        *flo2hex(char *, double *, int);
  677. void        flotobig(double, BIGDATA *);
  678. void        fluid_lookup(REGPTR);
  679. void        fmt_regs(int);
  680. void        force_call(void);
  681. void        force_reset(void);
  682. void        force_debug(void);
  683. void        force_timeout(void);
  684. int        formflo(char *, BIGDATA *, int, int, int);
  685. void        fperror(int, int, int *);
  686. unsigned long    freesp(void);
  687.  
  688. void        garbage(void);
  689. void        gcmark(unsigned, unsigned);
  690. void        gcsquish(void);
  691. void        gcsweep(void);
  692. void        gc_off(void);
  693. void        gc_oht(void);
  694. void        gc_on(int);
  695. unsigned char    get_byte(unsigned, unsigned);
  696. int        get_max_cols(void);
  697. int        get_max_rows(void);
  698. void        get_maxenv( REGPTR );
  699. int        get_mode(REGPTR);
  700. int        get_port(REGPTR, int);
  701. void        get_prop(REGPTR, REGPTR);
  702. void        get_str(char *, unsigned, unsigned);
  703. unsigned    get_word(unsigned, unsigned);
  704. void        get_sym(char *, unsigned, unsigned);
  705. unsigned    getbase(unsigned);
  706. char        GETCH(void);
  707. int        GETCHready(void);
  708. int        gethistory(REGPTR);
  709. unsigned    gettype(REGPTR);
  710. void        givechar(char);
  711. int        graphit(int, ...);
  712. void        gvchars(char *, unsigned);
  713.  
  714. unsigned    hash(char *, int);
  715.  
  716. char        *ifile(char *, int);
  717. char        *ilookup(char *, int, unsigned, unsigned);
  718. int        initmem(void);
  719. long        int2long(REGPTR);
  720. void        intern(REGPTR, char *, int);
  721. RETVALUE    interp(unsigned *, unsigned *, unsigned);
  722. int        isdig(int, int);
  723. int        is_graph_mode(void);
  724. int        iswhitespace(char);
  725.  
  726. void        ldreg(REGPTR, unsigned, unsigned);
  727. int        link(LINKVAL *, int, LINKARG *);
  728. void        long2int(REGPTR, long);
  729.  
  730. int        magcomp(BIGDATA *, BIGDATA *);
  731. void        make_ptr(unsigned, unsigned);
  732. int        makeflo(double, BIGDATA *, int, int);
  733. int        make_port(REGPTR, REGPTR);
  734. void        malloc_error(char *);
  735. void        mark(void);
  736. int        match(REGPTR, char **);
  737. void        matchdone( void );
  738. int        mov_fptr(int);
  739. int        mcmpstr(REGPTR, REGPTR);
  740. void        msubstr(REGPTR, REGPTR, unsigned, unsigned);
  741.  
  742. unsigned char    next_byte(void);
  743. unsigned    next_word(void);
  744. double        next_flonum(void);
  745. void        newport(REGPTR, REGPTR);
  746. void        nosound(void);
  747. void        not_fluidly_bound(unsigned, unsigned, REGPTR);
  748. void        not_globally_bound(unsigned, unsigned, REGPTR);
  749. void        not_lexically_bound(unsigned, unsigned);
  750. void        not_number(int, REGPTR, REGPTR);
  751. void        not_procedural(REGPTR, int);
  752.  
  753. void        objhash(REGPTR);
  754. void        objunhash(REGPTR);
  755. void        out_of_memory(void);
  756. int        outrange(double);
  757.  
  758. void    _seg    *page2c(unsigned);
  759. void        parse_files(int *, char ***, char **);
  760. void        pclose(REGPTR);
  761. int        plock(REGPTR);
  762. int        popen(REGPTR);
  763. int        port_char_ready(REGPTR);
  764. int        port_get_attribute(REGPTR, REGPTR);
  765. int        port_peek_char(REGPTR);
  766. int        port_read_char(REGPTR);
  767. int        port_read_line(REGPTR);
  768. int        port_set_attribute(REGPTR, REGPTR, REGPTR);
  769. void        print_and_exit(char *);
  770. void        printatm(unsigned, unsigned, unsigned, char);
  771. void        printchar(int);
  772. void        printflo(double);
  773. void        printstr(char *, int);
  774. int        prop_list(REGPTR);
  775. int        prop_search(REGPTR, REGPTR);
  776. void        prt_atr(unsigned);
  777. void        prt_free(unsigned *, unsigned *);
  778. void        prt_unused(unsigned *, unsigned *);
  779. void        ptime(REGPTR);
  780. void        punlock(REGPTR);
  781. void        pushchar(void);
  782. int        pushhistory(REGPTR);
  783. void        put_byte(unsigned, unsigned, unsigned char);
  784. void        put_str(char *, unsigned, unsigned);
  785. void        put_sym(char *, unsigned, unsigned, unsigned, unsigned, unsigned);
  786. int        put_prop(REGPTR, REGPTR, REGPTR);
  787. void        put_ptr(int, int, int, int);
  788. void        put_word(unsigned, unsigned, unsigned);
  789. void        putlong(REGPTR, long);
  790.  
  791. int        read_constant(void);
  792. int        read_win(void);
  793. SCHEMEOBJ    reg2c(REGPTR);
  794. int        regstrlen(REGPTR);
  795. int        reif_stk(REGPTR, int, int);
  796. int        reify(int, REGPTR, REGPTR, REGPTR);
  797. void        rel_reg(REGPTR);
  798. void        rem_prop(REGPTR, REGPTR);
  799. void        reset_fasl(void);
  800. void        rest_scr(REGPTR, int, int);
  801. void        restart(int);
  802. void        rlsstr(char *);
  803. long        rsttimer(void);
  804. int        run(unsigned *, unsigned *, unsigned);    /* same as interp */
  805.  
  806. int        sappend(REGPTR, REGPTR);
  807. void        save_scr(REGPTR, int, int, int, int );
  808. void        scale(double *, int *);
  809. void        scanflo(char *, double *, int);
  810. int        scannum(char *, int);
  811. SCHEMEOBJ    scheme2c(unsigned, unsigned);
  812. void        scheme_error(void);
  813. void        scheme_reset(void);
  814. int        scm2bool(REGPTR);
  815. RETVALUE    sdebug(unsigned *);
  816. int        sequal_p(REGPTR, REGPTR);
  817. void        set_error(int, char *, REGPTR);
  818. void        set_numeric_error(int, int, REGPTR);
  819. int        set_pos(REGPTR, int, int);
  820. void        set_src_error(char *, int, ...);
  821. int        set_window_attribute(REGPTR, REGPTR, REGPTR);
  822. int        settimer(unsigned, unsigned);
  823. int        sfloat(REGPTR);
  824. char        sgetc(void);
  825. void        sound(unsigned);
  826. int        spclose(REGPTR);
  827. int        spopen(REGPTR, REGPTR);
  828. void        sprint(unsigned, unsigned, unsigned, unsigned);
  829. void        sprint_reg(unsigned, unsigned, unsigned);
  830. void        srandom(REGPTR);
  831. int        srch_str(REGPTR, REGPTR, REGPTR, REGPTR, int);
  832. void        sread_atom(REGPTR, unsigned, unsigned);
  833. void        sread_ln(REGPTR, unsigned, unsigned);
  834. void        srelocat(void);
  835. void        ssetadr(unsigned, unsigned);
  836. int        ssubstr(REGPTR, REGPTR, REGPTR);
  837. int        st_len(REGPTR);
  838. void            stk_ovfl(void);
  839. unsigned    stkspc(void);
  840. void        stringrd(unsigned, unsigned, char *, int *);
  841. int        str_2_sym(REGPTR);
  842. int        str_2_usym(REGPTR);
  843. int        str_apnd(REGPTR, REGPTR, REGPTR, REGPTR, REGPTR, REGPTR, REGPTR);
  844. int        str_disp(REGPTR, REGPTR, REGPTR, REGPTR, REGPTR);
  845. int        str_srch_str(REGPTR, REGPTR, REGPTR, REGPTR, int);
  846. void        str2str(void *, void *, int);
  847. char        *string_asciz(REGPTR);
  848. void        sum_space(unsigned *);
  849. int        sym_2_str(REGPTR);
  850. int        sym_eq(unsigned, unsigned, char *, int);
  851. void        sym_undefined(unsigned, unsigned, REGPTR, REGPTR);
  852. char        *symbol_name(unsigned, unsigned);
  853. unsigned    sw_int(unsigned char, unsigned, unsigned, unsigned, unsigned);
  854. void        swpage(unsigned);
  855. void        sym_bind(REGPTR, REGPTR, REGPTR);
  856. int        sym_hash(REGPTR);
  857. int        sym_lookup(REGPTR, REGPTR);
  858. void        sym_search(REGPTR);
  859.  
  860. RETVALUE    t_inst(unsigned, unsigned *, unsigned *, int);
  861. void        take_car(REGPTR);
  862. void        take_cdr(REGPTR);
  863. char        take_ch(void);
  864. void        thefix(BIGDATA *);
  865. void        toblock(REGPTR, int, void *, unsigned);
  866. void        togglegc(void);
  867.  
  868. void        unfixint(void);
  869.  
  870. void        who_write(char *);
  871. void        wrap(int);
  872. void        wrong_args(int, REGPTR);
  873.  
  874. void        zap_chars(REGPTR, unsigned, unsigned);
  875. void        zautohiding(int);
  876. void        zbell(void);
  877. void        zborder(int, int, int, int, int, char *);
  878. void        zclear(int, int, int, int, int);
  879. int        zclose(int);
  880. int        zcreate(int *, char *);
  881. void        zcuroff(void);
  882. void        zcuron(void);
  883. void        zero_blk(unsigned, unsigned);
  884. void        zero_page(unsigned);
  885. int        zopen(int *, char *, int, unsigned long *);
  886. void        zprintf(char *, ...);
  887. int        zputc(int, int, int, int, int *);
  888. void        zputcur(int, int);
  889. int        zread(int, void *, int *);
  890. void        zscroll(int, int, int, int, int);
  891. void        zscroll_d(int, int, int, int, int);
  892. int        zwrite(int, void *, int *);
  893.  
  894. }
  895.  
  896.